#pragma once

#include <string>
#include "../util.hpp"

namespace pharmacy_server
{
    struct SalesRecord
    {
        using tuple_of_record = std::tuple<std::string, std::string, int, std::string, std::string>;

        SalesRecord(const std::string& username, const std::string& medicine_name, int quantity, const std::string& action, const std::string& sale_date)
            : username(username)
            , medicine_name(medicine_name)
            , quantity(quantity)
            , action(action)
            , sale_date(sale_date)
        {
        }

        SalesRecord(const tuple_of_record& tuple)
        {
            from_tuple(tuple);
        }

        std::string username;
        std::string medicine_name;
        int quantity;
        std::string action;
        std::string sale_date;

        Json::Value to_json() const
        {
            Json::Value root;
            root["username"] = username;
            root["medicine_name"] = medicine_name;
            root["quantity"] = quantity;
            root["action"] = action;
            root["sale_date"] = sale_date;
            return root;
        }

        void from_json(const Json::Value& root)
        {
            username = root["username"].asString();
            medicine_name = root["medicine_name"].asString();
            quantity = root["quantity"].asInt();
            action = root["action"].asString();
            sale_date = root["sale_date"].asString();
        }

        tuple_of_record to_tuple() const
        {
            return std::make_tuple(username, medicine_name, quantity, action, sale_date);
        }

        void from_tuple(const tuple_of_record& line)
        {
            username = std::get<0>(line);
            medicine_name = std::get<1>(line);
            quantity = std::get<2>(line);
            action = std::get<3>(line);
            sale_date = std::get<4>(line);
        }

        static SalesRecord from_tuple_quickly(const tuple_of_record& line)
        {
            return SalesRecord(std::get<0>(line), std::get<1>(line), std::get<2>(line), std::get<3>(line), std::get<4>(line));
        }

    };
}